﻿module HostReflectionTests

open NUnit.Framework
open HostObjectReflection
open JsEngine
open JsTypes
open ScriptingExposedAttribute

type DummyHostObject() =

    [<ScriptingExposed>]
    member public this.explode(str:string) =
        "*" + str + "*"

    [<ScriptingExposed>]
    member public this.name = "boom"


[<TestFixture>]
type testJsEngine() =

    [<Test>]
    member self.testExecJs() =
        let h = HostObjectWrapper(DummyHostObject()) :> IObject
        let size = h.Get("name")
        Assert.AreEqual(StringValue("boom"), size)

        // method
        let (Object(ho)) = h.Get("explode")
        let value2 = ho.Call Undefined [StringValue("hello")]
        Assert.AreEqual(StringValue("*hello*"), value2)

        // default if missing value
        Assert.AreEqual(StringValue("*undefined*"), ho.Call Undefined [])
    
